import 'package:get/get.dart';
import 'package:meePet/app//RouteConstants.dart';
import 'package:meePet/manager/RouteManager.dart';
import 'package:meePet/manager/TabConfigManager.dart';
import 'package:meePet/manager/UserManager.dart';
import 'package:meePet/utils/LogUtils.dart';

class SplashVM extends GetxController {
  @override
  void onInit() {
    super.onInit();
  }

  @override
  void onReady() {
    ///太快了，留点时间给sp做全局初始化
    Future.delayed(Duration(milliseconds: 100),(){
      if(UserManager.get().isLogin()){
        LogUtils.i("用户已登录，无需重复登录");
        ///获取完tab配置后再跳转
        TabConfigManager.getInstance().getConfig().then((value) => {
          LogUtils.i("获取完tab配置后再跳转:" + value),
          jumpToMainPage(params: {"data": value})
        });
      }else{
        LogUtils.i("用户未登录，走登录流程");
        TabConfigManager.getInstance().getConfig().then((value) => {
        RouteManager.off(RouteConstants.loginPage)
        });
        //LoginManager.getInstance().smsLogin("15625059242","123456",null);

      }
    });
    super.onReady();
  }

  @override
  void onClose() {
    super.onClose();
  }

  void jumpToMainPage({Map<String, String>? params}) {
    RouteManager.off(RouteConstants.mainPage, mParams: params);
  }
}
